from datetime import datetime
from pydantic import Field, ConfigDict
from enum import IntEnum
from .base import BaseSchema

class GoodsStatus(IntEnum):
    """商品状态枚举"""
    DISABLED = 0
    ENABLED = 1

class GoodsBase(BaseSchema):
    """商品基础模型"""
    code: str | None = Field(None, description="商品编码", max_length=50)
    name: str = Field(..., description="商品名称", max_length=255)
    category: str | None = Field(None, description="商品类别", max_length=50)
    status: GoodsStatus = Field(
        default=GoodsStatus.ENABLED,
        description="商品状态：1-正常，0-下架"
    )

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "code": "APPLE-001",
                "name": "iPhone 13",
                "category": "手机",
                "status": 1
            }
        }
    )

class GoodsCreate(GoodsBase):
    """创建商品请求模型"""
    code: str | None = Field(
        default=None,
        description="商品编码(如不提供将自动生成)",
        max_length=50
    )

class GoodsUpdate(BaseSchema):
    """更新商品请求模型"""
    code: str | None = Field(None, description="商品编码", max_length=50)
    name: str | None = Field(None, description="商品名称", max_length=255)
    category: str | None = Field(None, description="商品类别", max_length=50)
    status: GoodsStatus | None = Field(
        None,
        description="商品状态：1-正常，0-下架"
    )

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "code": "APPLE-001",
                "name": "iPhone 13",
                "category": "手机",
                "status": 1
            }
        }
    )

class GoodsResponse(GoodsBase):
    """商品响应模型"""
    id: int
    create_at: datetime
    update_at: datetime

    model_config = ConfigDict(
        json_schema_extra={
            "example": {
                "id": 1,
                "code": "APPLE-001",
                "name": "iPhone 13",
                "category": "手机",
                "status": 1,
                "create_at": "2024-01-01T00:00:00",
                "update_at": "2024-01-01T00:00:00"
            }
        }
    )